import { Col, Row, Space } from 'antd';
import React, { useEffect, useState } from 'react'
import Add from '../components/order/Add';
import Search from '../components/order/Search';
import List from '../components/order/List';
import { find } from '../services/order';
import Update from '../components/order/Update';
import Detail from '../components/order/Detail';
import ReceiveModal from '../components/order/ReceiveModal';

export default function Order() {
    let [orderData, setOrderData] = useState([]);
    let [pagination, setPagination] = useState({
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: (total) => `总共 ${total} 条`,
        pageSizeOptions: [5, 10, 15, 20],
    });

    let [searchObj, setSearchObj] = useState({});

    const show = async (params) => {
        if (params) {
            if (!params.current) {
                params.current = 1;
                params.pageSize = pagination.pageSize;
            }
            params = { ...searchObj, ...params };
            setSearchObj(params);
        } else {
            params = searchObj;
        }
        let { data } = await find(params);

        setOrderData(data.rows);
        setPagination({
            ...pagination,
            total: data.total,
            current: parseInt(data.current),
            pageSize: data.pageSize,
        });
    };

    useEffect(() => {
        show();
    }, [orderData.length])

    return (
        <>
            <Row>
                <Space>
                    {/* <Col span={1}>
                        <Add show={show}></Add>
                    </Col> */}
                    <Col span={8}>
                        <Search show={show}></Search>
                    </Col>
                </Space>
            </Row>
            <Update show={show} />
            <Detail />
            <ReceiveModal />
            <List show={show} orderData={orderData} pagination={pagination} />
        </>
    )
}
